package com.usian.admin.controller.v1;

import com.usian.admin.service.WemediaNewsAutoService;
import com.usian.common.dtos.PageResult;
import com.usian.common.dtos.ResponseResult;
import com.usian.model.admin.dtos.NewsAuthDto;
import com.usian.model.media.dtos.WmNewsResultDTO;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/news_auth")
public class NewsAuthController {

    @Autowired
    private WemediaNewsAutoService wemediaNewsAutoService;

    /*
    * 分页条件查询自媒体文章列表
    * */
    @PostMapping("/list")
    public PageResult<WmNewsResultDTO> findWmNewsByPage(@RequestBody NewsAuthDto dto){
        return wemediaNewsAutoService.findPage(dto);
    }

    /*
    * 查询一条自媒体文章信息
    * */
    @GetMapping("/one/{id}")
    public ResponseResult<WmNewsResultDTO> findByWmNewsId(@PathVariable(name = "id")Integer id){

        return wemediaNewsAutoService.findByWmNewsId(id);
    }

    /*
    * 人工审核通过
    * */
    @PostMapping("/auth_pass")
    public ResponseResult authPass(@RequestBody NewsAuthDto dto){
        wemediaNewsAutoService.updateWmNews(dto.getId(),"通过",WmNewsResultDTO.Status.ADMIN_SUCCESS.getCode());
        return ResponseResult.ok();
    }

    /*
    * 人工审核未通过
    * */
    @PostMapping("/auth_fail")
    public ResponseResult authFail(@RequestBody NewsAuthDto dto){
        wemediaNewsAutoService.updateWmNews(dto.getId(),dto.getMsg(),WmNewsResultDTO.Status.FAIL.getCode());
        return ResponseResult.ok();
    }

}
